﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;

namespace UIDevCore
{
    public class UIPremission
    {
        public const string cost_SessionName = "CurrentUser";

        private IClient _CurrentUser;
        public IClient CurrentUser
        {
            get
            {
                if (_CurrentUser == null)
                    _CurrentUser = HttpContext.Current.Session[cost_SessionName] as IClient;

                return _CurrentUser;
            }
        }

        public bool IsLogin
        {
            get { return this.CurrentUser != null; }
        }

        public static void SetCurrentUser(IClient member)
        {
            HttpContext.Current.Session[cost_SessionName] = member;
        }

        public virtual UIEmnus.EError CheckRight(string Roles)
        {
            if (!string.IsNullOrEmpty(Roles))
            {
                if (this.IsLogin)
                {
                    return CommonUtility.Utility.CommonHelper.ContainValue(Roles, this._CurrentUser.Role)
                        ? UIEmnus.EError.NoError : UIEmnus.EError.NoRight;
                }
                else
                    return UIEmnus.EError.NoLogin;
            }
            else
                return UIEmnus.EError.NoError;
        }
    }
}
